package com.eastfair.certificate.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.auth.api.UserAccountServiceFeign;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.auth.entity.UserAccount;
import com.eastfair.auth.vo.UserAccountVo;
import com.eastfair.boot.request.PageParams;
import com.eastfair.boot.service.SuperCacheServiceImpl;
import com.eastfair.cache.certificate.CertificateUserCacheKeyBuilder;
import com.eastfair.certificate.dao.CertificateUserMapper;
import com.eastfair.certificate.dto.CertificateDTO;
import com.eastfair.certificate.dto.CertificateOrderDTO;
import com.eastfair.certificate.dto.CertificateUserDTO;
import com.eastfair.certificate.dto.PeopleDTO;
import com.eastfair.certificate.entity.Blacklist;
import com.eastfair.certificate.entity.Certificate;
import com.eastfair.certificate.entity.CertificateUser;
import com.eastfair.certificate.entity.People;
import com.eastfair.certificate.enumeration.*;
import com.eastfair.certificate.exceptioncode.CertificateExceptionCode;
import com.eastfair.certificate.service.CertificateIndexService;
import com.eastfair.certificate.service.CertificateService;
import com.eastfair.certificate.service.CertificateUserService;
import com.eastfair.boot.service.SuperServiceImpl;

import com.eastfair.certificate.service.PeopleService;
import com.eastfair.certificate.vo.CertificateUserVO;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.context.StaticContextUtil;
import com.eastfair.core.exception.BizException;
import com.eastfair.core.exception.NoBackBizException;
import com.eastfair.core.model.CacheKeyBuilder;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.database.mybatis.conditions.Wraps;
import com.eastfair.database.mybatis.conditions.query.QueryWrap;
import com.eastfair.database.mybatis.typehandler.TypeHandlerUtil;
import com.eastfair.messagecenter.util.SendMsgUtil;
import com.eastfair.projectcore.enumeration.DataIsolationSystemSceneEnum;
import com.eastfair.venuebooking.api.ExhibitionManageFeign;
import com.eastfair.venuebooking.api.ServiceProviderFeign;
import com.eastfair.venuebooking.dto.CustomerMainUpdateDTO;
import com.eastfair.venuebooking.entity.CustomerMain;
import com.eastfair.venuebooking.vo.ExhibitionSpaceVO;
import com.eastfair.venueservice.dto.ExhibitionManageQuery;
import com.eastfair.venueservice.dto.ServiceProviderDTO;
import com.eastfair.venueservice.entity.ServiceProvider;
import com.eastfair.venueservice.vo.ExhibitionManageVO;
import com.eastfair.venueservice.vo.ServiceProviderVO;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;

import java.util.*;

//import com.baomidou.dynamic.datasource.annotation.DS;
import org.springframework.aop.framework.AopContext;
import com.eastfair.annotation.annotation.cache.Magic;
import com.eastfair.annotation.annotation.cache.Cache;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
//import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.stream.Collectors;

/**
 * <p>
 * 业务实现类
 * 用户填写的制证信息
 * </p>
 *
 * @author ligang
 * @date 2022-07-28
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class CertificateUserServiceImpl extends SuperCacheServiceImpl<CertificateUserMapper, CertificateUser> implements CertificateUserService {

    @Autowired
    private CertificateService certificateService;

    @Autowired
    ServiceProviderFeign serviceProviderFeign;

    @Autowired
    ExhibitionManageFeign exhibitionManageFeign;

    @Autowired
    CertificateIndexService certificateIndexService;


    @Autowired
    PeopleService peopleService;

    @Autowired
    SendMsgUtil sendMsgUtil;

    @Autowired
    UserAccountServiceFeign userAccountServiceFeign;

    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<CertificateUser> modelList) {
        modelList.stream().forEach(s -> {
            s.setIsDeleted(BusinessConstant.YES);
        });
        // TODO: 2021/10/29 这里需要操作其他业务，如清空角色等
        return R.successDef();
    }

    /**
     * 处理新增相关处理
     *
     * @param model 实体
     * @return 是否成功
     */
    @Override
    public R<Boolean> handlerSave(CertificateUser model) {
        model.setProjectId(ContextUtil.getProjectId());
        model.setSubsystemId(ContextUtil.getSubSystemId());
        model.setTeamId(ContextUtil.getTeamId());
        model.setIsDeleted(BusinessConstant.NO);
        model.setIsEnabled(BusinessConstant.YES);
        //雪花ID
        return R.successDef();
    }


    public R<CertificateUser> handlerUpdate(CertificateUser model) {
        // 是否同步
        model.setIsSycn(BusinessConstant.NO);
        return R.successDef();
    }


    @Override
    public CertificateUser submitForm(CertificateUserDTO certificateUserDTO) {
        if (certificateUserDTO.getId() != null) {
            //更新
            CertificateUser certificateUser = new CertificateUser();
            BeanUtils.copyProperties(certificateUserDTO, certificateUser);
            certificateUser.setId(certificateUserDTO.getId());
            //非制证系统修改时，需要重置审核状态，重新审核
            if (!DataIsolationSystemSceneEnum.P_CERTIFICATE.getCode().equals(ContextUtil.getSystemScene())) {
                CertificateUser certificateUser2 = getByIdCache(certificateUserDTO.getId());
                if (certificateUser2 != null && certificateUser2.getOrderId() == null) {
                    if (certificateUser2.getFirstAuthId() != null) {
                        certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK);
                    } else {
                        certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
                    }
                    //组装终审审核状态
                    Certificate certificate = certificateService.getById(certificateUser.getCertificateId());
                    assmbleSecondAuthStatus(certificate, certificateUser);
                    if (!CertificateUserFirstAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getFirstAuthStatus()) ||
                            !CertificateUserSecondAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getSecondAuthStatus())) {
                        certificateUser.setCertificateStatus(CertificateUserCertificateStatusEnum.AUTH);
                    }
                }
            }
            //操作人员库
            executePeople(certificateUser);
            updateById(certificateUser);
        } else {
            CertificateUser certificateUser = new CertificateUser();
            BeanUtils.copyProperties(certificateUserDTO, certificateUser);
            //加载审核信息
            Certificate certificate = certificateService.getById(certificateUserDTO.getCertificateId());
            certificateUser.setExhibitionId(certificate.getExhibitionId());
            certificateUser.setCertificateType(CertificateUserCertificateTypeEnum.get(certificate.getCertificateType().getCode()));

            //组装初次审核状态
            assmbleFirstAuthStatus(certificate, certificateUser);
            //组装终审审核状态
            assmbleSecondAuthStatus(certificate, certificateUser);

            if (CertificateUserSecondAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getSecondAuthStatus())) {
                //状态：待提交
                certificateUser.setCertificateStatus(CertificateUserCertificateStatusEnum.SUBMIT);
                //更新使用数量
                if (StringUtils.isNotBlank(certificateUser.getSpaceCode())) {
                    certificateIndexService.addIndex(certificate.getId(), certificateUser.getSpaceCode(), certificateUser.getComeInTime(), 1);
                }
            }
            if (certificateUser.getCertificateStatus() == null) {
                //状态：待审核
                certificateUser.setCertificateStatus(CertificateUserCertificateStatusEnum.AUTH);
            }
            if (CertificateUserFirstAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getFirstAuthStatus()) &&
                    CertificateUserSecondAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getSecondAuthStatus())) {
                certificateUser.setCertificateStatus(CertificateUserCertificateStatusEnum.SUBMIT);
            }

            certificateUser.setIsCancel(BusinessConstant.NO);
            certificateUser.setIsLoss(BusinessConstant.NO);
            certificateUser.setIsDraw(BusinessConstant.NO);
            certificateUser.setIsBlack(BusinessConstant.NO);
            certificateUser.setIsPay(BusinessConstant.NO);
            certificateUser.setIsSycn(BusinessConstant.NO);
            certificateUser.setIsPrintTake(BusinessConstant.NO);
            String systemScene = ContextUtil.getSystemScene();
            certificateUser.setResourceType(CertificateUserResourceTypeEnum.ONLINE);
            certificateUser.setAppointmentInStartTime(certificateUser.getComeInTime());
            if (DataIsolationSystemSceneEnum.P_CERTIFICATE.getCode().equals(systemScene)) {
                //制证：初次审核自动通过
                certificateUser.setResourceType(CertificateUserResourceTypeEnum.SPOT);
            }
            certificateUser.setDataResource(CertificateUserDataResourceEnum.CENTIFICATE);
            //操作人员库
            executePeople(certificateUser);
            save(certificateUser);
            return certificateUser;
        }
        return null;
    }

    public void executePeople(CertificateUser certificateUser) {
        PeopleDTO peopleDTO = new PeopleDTO();
        BeanUtils.copyProperties(certificateUser, peopleDTO);
        peopleDTO.setId(null);
        peopleService.executePeople(peopleDTO);
    }

    public void assmbleFirstAuthStatus(Certificate certificate, CertificateUser certificateUser) {
        //初始化数据
        certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK);
        certificateUser.setFirstAuthId(certificate.getFirstAuthId());
        if (certificate.getFirstAuthId() == null) {
            //不用初次审核
            certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
        }
        String systemScene = ContextUtil.getSystemScene();
        if (DataIsolationSystemSceneEnum.P_COMPOSITE_COURT.getCode().equals(systemScene)) {
            //主场：初次审核自动通过
            certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
        } else if (DataIsolationSystemSceneEnum.P_CERTIFICATE.getCode().equals(systemScene)) {
            //制证：初次审核自动通过
            certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
        }

//        //人证不审核
//        if (CertificateCertificateTypeEnum.PEOPLE.eq(certificate.getCertificateType())) {
//            certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
//        }
    }

    public void assmbleSecondAuthStatus(Certificate certificate, CertificateUser certificateUser) {
        //初始化数据
        certificateUser.setSecondAuthId(certificate.getSecondAuthId());
        if (certificate.getSecondAuthId() == null) {
            //不用终审
            certificateUser.setSecondAuthStatus(CertificateUserSecondAuthStatusEnum.CHECK_SUCC);
            if (CertificateUserFirstAuthStatusEnum.CHECK.eq(certificateUser.getFirstAuthStatus())
                    || CertificateUserFirstAuthStatusEnum.CHECK_FAIL.eq(certificateUser.getFirstAuthStatus())) {
                certificateUser.setSecondAuthStatus(CertificateUserSecondAuthStatusEnum.WAIT);
            }
        } else {
            certificateUser.setSecondAuthStatus(CertificateUserSecondAuthStatusEnum.CHECK);
            if (certificate.getFirstAuthId() != null && CertificateUserFirstAuthStatusEnum.CHECK.eq(certificateUser.getFirstAuthStatus())) {
                certificateUser.setSecondAuthStatus(CertificateUserSecondAuthStatusEnum.WAIT);
            }
        }
        String systemScene = ContextUtil.getSystemScene();
        if (DataIsolationSystemSceneEnum.P_CERTIFICATE.getCode().equals(systemScene)) {
            //制证：审核自动通过
            certificateUser.setSecondAuthStatus(CertificateUserSecondAuthStatusEnum.CHECK_SUCC);
        }
//        //人证不审核
//        if (CertificateCertificateTypeEnum.PEOPLE.eq(certificate.getCertificateType())) {
//            certificateUser.setFirstAuthStatus(CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
//        }
    }

    @Override
    public List<CertificateUser> firstAuthForm(CertificateUserDTO certificateUserDTO) {
        List<CertificateUser> certificateUserList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(certificateUserDTO.getIds())) {
            certificateUserList = list(null, certificateUserDTO.getIds());
        }
        if (certificateUserDTO.getCertificateId() != null) {
            CertificateUser certificateUser = getByIdCache(certificateUserDTO.getCertificateId());
            certificateUserList.add(certificateUser);
        }

        if (CollectionUtil.isNotEmpty(certificateUserList)) {
            for (CertificateUser certificateUser : certificateUserList) {
                if (certificateUser.getIsBlack() != null && BusinessConstant.YES == certificateUser.getIsBlack()) {
                    throw NoBackBizException.wrap(CertificateExceptionCode.BLACK);
                }
            }
        }


        for (CertificateUser certificateUser : certificateUserList) {
            if (certificateUser.getFirstAuthId() == null) {
                //不需要初次审核
                throw NoBackBizException.wrap(CertificateExceptionCode.FIRST_AUTH_NULL);
            }
        }
        for (CertificateUser certificateUser : certificateUserList) {
            certificateUser.setFirstAuthStatus(certificateUserDTO.getFirstAuthStatus());
            certificateUser.setFirstAuthText(certificateUserDTO.getFirstAuthText());
            Certificate certificate = certificateService.getById(certificateUser.getCertificateId());
            assmbleSecondAuthStatus(certificate, certificateUser);
            //最终状态
            certificateUser.setCertificateStatus(assmbleStatus(certificateUser));
            updateById(certificateUser);
        }
        //发送短信
        sendSmsOfFileAuth(certificateUserList, 1);
        //更新使用数量
        executeCertificateIndex(certificateUserList);
        return certificateUserList;
    }

    public void sendSmsOfFileAuth(List<CertificateUser> certificateUserList, Integer authNum) {
        if (CollectionUtil.isEmpty(certificateUserList)) {
            return;
        }
        UserAccountDto userAccountDto = new UserAccountDto();
        userAccountDto.setUserIds(certificateUserList.stream().map(CertificateUser::getCreatedBy).collect(Collectors.toList()));
        R<List<UserAccountVo>> listR = userAccountServiceFeign.querySimpleByIds(userAccountDto);
        if (!listR.getIsSuccess()) {
            return;
        }
        List<UserAccountVo> userAccountVoList = listR.getData();
        if (CollectionUtil.isEmpty(userAccountVoList)) {
            return;
        }
        String content = "";
        Set<String> mobileSet = new HashSet<>();
        for (CertificateUser certificateUser : certificateUserList) {
            List<UserAccountVo> userAccountVoList2 = userAccountVoList.stream().filter(s -> s.getId().equals(certificateUser.getCreatedBy())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(userAccountVoList2)) {
                if (authNum == 1) {
                    if (CertificateUserFirstAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getFirstAuthStatus())) {
                        content = "证件审核通过";
                    } else if (CertificateUserFirstAuthStatusEnum.CHECK_FAIL.eq(certificateUser.getFirstAuthStatus())) {
                        content = "证件审核不通过,原因：" + certificateUser.getFirstAuthText();
                    }
                } else if (authNum == 2) {
                    if (CertificateUserSecondAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getSecondAuthStatus())) {
                        content = "证件审核通过";
                    } else if (CertificateUserSecondAuthStatusEnum.CHECK_FAIL.eq(certificateUser.getSecondAuthStatus())) {
                        content = "证件审核不通过,原因：" + certificateUser.getSecondAuthText();
                    }
                }
                mobileSet.add(userAccountVoList2.get(0).getMobile());
            }
        }
//        sendMsgUtil.sendSms(mobileSet, content);
    }

    @Override
    public List<CertificateUser> secondAuthForm(CertificateUserDTO certificateUserDTO) {
        List<CertificateUser> certificateUserList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(certificateUserDTO.getIds())) {
            certificateUserList = list(null, certificateUserDTO.getIds());
        }
        if (certificateUserDTO.getCertificateId() != null) {
            CertificateUser certificateUser = getByIdCache(certificateUserDTO.getCertificateId());
            certificateUserList.add(certificateUser);
        }
        if (CollectionUtil.isNotEmpty(certificateUserList)) {
            for (CertificateUser certificateUser : certificateUserList) {
                if (certificateUser.getIsBlack() != null && BusinessConstant.YES == certificateUser.getIsBlack()) {
                    throw NoBackBizException.wrap(CertificateExceptionCode.BLACK);
                }
            }
        }
        for (CertificateUser certificateUser : certificateUserList) {
            if (certificateUser.getSecondAuthId() == null) {
                //不需要最终审核
                throw NoBackBizException.wrap(CertificateExceptionCode.SECOND_AUTH_NULL);
            }
            if (CertificateUserFirstAuthStatusEnum.CHECK.eq(certificateUser.getFirstAuthStatus())) {
                //请先完成初审
                throw NoBackBizException.wrap(CertificateExceptionCode.FIRST_AUTH_CHECK);
            } else if (CertificateUserFirstAuthStatusEnum.CHECK_FAIL.eq(certificateUser.getFirstAuthStatus())) {
                //初审失败，不能审核
                throw NoBackBizException.wrap(CertificateExceptionCode.FIRST_AUTH_CHECK_FAIL);
            }
        }
        for (CertificateUser certificateUser : certificateUserList) {
            certificateUser.setSecondAuthStatus(certificateUserDTO.getSecondAuthStatus());
            certificateUser.setSecondAuthText(certificateUserDTO.getSecondAuthText());
            //最终状态
            certificateUser.setCertificateStatus(assmbleStatus(certificateUser));
            updateById(certificateUser);
        }
        //发送短信
        sendSmsOfFileAuth(certificateUserList, 2);
        //更新使用数量
        executeCertificateIndex(certificateUserList);
        return certificateUserList;
    }


    public CertificateUserCertificateStatusEnum assmbleStatus(CertificateUser certificateUser) {
        if (CertificateUserSecondAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getSecondAuthStatus()) &&
                CertificateUserFirstAuthStatusEnum.CHECK_SUCC.eq(certificateUser.getFirstAuthStatus())) {
            return CertificateUserCertificateStatusEnum.SUBMIT;
        }
        if (CertificateUserFirstAuthStatusEnum.CHECK_FAIL.eq(certificateUser.getFirstAuthStatus())) {
            return CertificateUserCertificateStatusEnum.CHECK_FAIL;
        }

        if (CertificateUserSecondAuthStatusEnum.CHECK_FAIL.eq(certificateUser.getSecondAuthStatus())) {
            return CertificateUserCertificateStatusEnum.CHECK_FAIL;
        }
        return CertificateUserCertificateStatusEnum.AUTH;
    }

    public void executeCertificateIndex(List<CertificateUser> certificateUserList) {
        if (CollectionUtil.isEmpty(certificateUserList)) {
            return;
        }
        for (CertificateUser certificateUser : certificateUserList) {
            //更新使用数量
            if (StringUtils.isNotBlank(certificateUser.getSpaceCode())) {

                if (CertificateUserSecondAuthStatusEnum.CHECK_SUCC == certificateUser.getSecondAuthStatus()) {
                    certificateIndexService.addIndex(certificateUser.getCertificateId(), certificateUser.getSpaceCode(), certificateUser.getComeInTime(), 1);
                } else if (CertificateUserSecondAuthStatusEnum.CHECK_FAIL == certificateUser.getSecondAuthStatus()) {
                    certificateIndexService.addIndex(certificateUser.getCertificateId(), certificateUser.getSpaceCode(), certificateUser.getComeInTime(), -1);
                    //指标减1
                    Certificate certificate = certificateService.getByIdCache(certificateUser.getCertificateId());
                    certificate.setUseIndexNumber(Math.max((certificate.getUseIndexNumber() == null ? 0 : certificate.getUseIndexNumber()) - 1, 0));
                    certificateService.updateById(certificate);
                }
            }
        }
    }

    @Override
    public IPage<CertificateUserVO> pageFirstAuthForm(PageParams<CertificateUserDTO> params) {
        CertificateUserDTO certificateUserDTO = params.getModel();
        IPage<CertificateUser> page = params.buildPage();
        QueryWrapper<CertificateUser> queryWrapper = assembleQueryWrapper(certificateUserDTO);
        //page entity转vo
        IPage<CertificateUser> certificateUserIPage = page(page, queryWrapper);
        List<CertificateUserVO> certificateUserVOList = doToVos(certificateUserIPage.getRecords());
        //组装公司展会业务数据
        assembleBusinssData(certificateUserVOList);
        IPage<CertificateUserVO> certificateUserVOIPage = ConvertUtil.convertIPage(certificateUserIPage, certificateUserVOList);
        return certificateUserVOIPage;
    }

    @Override
    public List<CertificateUserVO> queryFirstAuthForm(CertificateUserDTO certificateUserDTO) {
        QueryWrapper<CertificateUser> queryWrapper = assembleQueryWrapper(certificateUserDTO);
        List<CertificateUser> certificateUserList = list(queryWrapper);
        List<CertificateUserVO> certificateUserVOList = doToVos(certificateUserList);
        //组装公司展会业务数据
//        assembleBusinssData(certificateUserVOList);
        return certificateUserVOList;
    }


    @Override
    public QueryWrapper<CertificateUser> assembleQueryWrapper(CertificateUserDTO certificateUserDTO) {
        QueryWrapper<CertificateUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(certificateUserDTO.getCertificateId() != null, CertificateUser::getCertificateId, certificateUserDTO.getCertificateId())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getPrincipalType()), CertificateUser::getPrincipalType, certificateUserDTO.getPrincipalType())
                .eq(certificateUserDTO.getCompanyId() != null, CertificateUser::getCompanyId, certificateUserDTO.getCompanyId())
                .like(StringUtils.isNotBlank(certificateUserDTO.getFullName()), CertificateUser::getFullName, "%" + certificateUserDTO.getFullName() + "%")
                .eq(StringUtils.isNotBlank(certificateUserDTO.getContactInformation()), CertificateUser::getContactInformation, TypeHandlerUtil.crypt(certificateUserDTO.getContactInformation()))
                .eq(certificateUserDTO.getExhibitorId() != null, CertificateUser::getExhibitorId, certificateUserDTO.getExhibitorId())
                .eq(certificateUserDTO.getCertificateType() != null, CertificateUser::getCertificateType, certificateUserDTO.getCertificateType())
                .in(certificateUserDTO.getIds() != null && !certificateUserDTO.getIds().isEmpty(), CertificateUser::getId, certificateUserDTO.getIds())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getCardNumber()), CertificateUser::getCardNumber, TypeHandlerUtil.crypt(certificateUserDTO.getCardNumber()))
                .like(StringUtils.isNotBlank(certificateUserDTO.getCarNumber()), CertificateUser::getCarNumber, "%" + certificateUserDTO.getCarNumber() + "%")
                .eq(certificateUserDTO.getCertificateStatus() != null, CertificateUser::getCertificateStatus, certificateUserDTO.getCertificateStatus())
                .eq(certificateUserDTO.getIsBlack() != null, CertificateUser::getIsBlack, certificateUserDTO.getIsBlack())
                .eq(certificateUserDTO.getIsCancel() != null, CertificateUser::getIsCancel, certificateUserDTO.getIsCancel())
                .eq(certificateUserDTO.getIsDraw() != null, CertificateUser::getIsDraw, certificateUserDTO.getIsDraw())
                .eq(certificateUserDTO.getIsLoss() != null, CertificateUser::getIsLoss, certificateUserDTO.getIsLoss())
                .eq(certificateUserDTO.getIsPay() != null, CertificateUser::getIsPay, certificateUserDTO.getIsPay())
                .eq(certificateUserDTO.getIsPower() != null, CertificateUser::getIsPower, certificateUserDTO.getIsPower())
                .eq(certificateUserDTO.getExhibitionId() != null, CertificateUser::getExhibitionId, certificateUserDTO.getExhibitionId())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getOrderNumber()), CertificateUser::getOrderNumber, certificateUserDTO.getOrderNumber())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getCarType()), CertificateUser::getCarType, certificateUserDTO.getCarType())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getCargoCapacity()), CertificateUser::getCargoCapacity, certificateUserDTO.getCargoCapacity())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getCargoMaterial()), CertificateUser::getCargoMaterial, certificateUserDTO.getCargoMaterial())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getTransportVariety()), CertificateUser::getTransportVariety, certificateUserDTO.getTransportVariety())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getWorkType()), CertificateUser::getWorkType, certificateUserDTO.getWorkType())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getDocumentType()), CertificateUser::getDocumentType, certificateUserDTO.getDocumentType())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getCertificateClassify()), CertificateUser::getCertificateClassify, certificateUserDTO.getCertificateClassify())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getPowerClassify()), CertificateUser::getPowerClassify, certificateUserDTO.getPowerClassify())
                .eq(StringUtils.isNotBlank(certificateUserDTO.getSpaceCode()), CertificateUser::getSpaceCode, certificateUserDTO.getSpaceCode())
                .eq(certificateUserDTO.getOrderId() != null, CertificateUser::getOrderId, certificateUserDTO.getOrderId())
                .ge(certificateUserDTO.getComeInStartTime() != null, CertificateUser::getComeInTime, certificateUserDTO.getComeInStartTime())
                .le(certificateUserDTO.getComeInEndTime() != null, CertificateUser::getComeInTime, certificateUserDTO.getComeInEndTime())
                .le(certificateUserDTO.getWorkEndTime() != null, CertificateUser::getWorkEndTime, certificateUserDTO.getWorkEndTime())
                .ge(certificateUserDTO.getWorkStartTime() != null, CertificateUser::getWorkStartTime, certificateUserDTO.getWorkStartTime())
                .ge(certificateUserDTO.getResourceType() != null, CertificateUser::getResourceType, certificateUserDTO.getResourceType())
                .in(CollectionUtil.isNotEmpty(certificateUserDTO.getCertificateTypes()), CertificateUser::getCertificateType, certificateUserDTO.getCertificateTypes())
                .isNotNull(certificateUserDTO.getIsCarNumberNotNull() != null, CertificateUser::getCarNumber)
                .le(certificateUserDTO.getAppointmentInEndTime() != null, CertificateUser::getAppointmentInEndTime, certificateUserDTO.getAppointmentInEndTime())
                .ge(certificateUserDTO.getAppointmentInEndTimeOfGe() != null, CertificateUser::getAppointmentInEndTime, certificateUserDTO.getAppointmentInEndTimeOfGe())

                .eq(certificateUserDTO.getIsSycn() != null, CertificateUser::getIsSycn, certificateUserDTO.getIsSycn())
                .eq(certificateUserDTO.getDataResource() != null, CertificateUser::getDataResource, certificateUserDTO.getDataResource())
                .eq(certificateUserDTO.getEUuid() != null, CertificateUser::getEUuid, certificateUserDTO.getEUuid())
                .eq(certificateUserDTO.getBooth() != null, CertificateUser::getBooth, certificateUserDTO.getBooth())
                .eq(certificateUserDTO.getIsPrintTake() != null, CertificateUser::getIsPrintTake, certificateUserDTO.getIsPrintTake())
                .eq(CertificateUser::getIsDeleted, BusinessConstant.NO);
        if (certificateUserDTO.getFirstAuthStatus() != null) {
            queryWrapper.lambda().eq(certificateUserDTO.getFirstAuthStatus() != null, CertificateUser::getFirstAuthStatus, certificateUserDTO.getFirstAuthStatus());
        }
        if (certificateUserDTO.getSecondAuthStatus() != null) {
            queryWrapper.lambda().eq(certificateUserDTO.getSecondAuthStatus() != null, CertificateUser::getSecondAuthStatus, certificateUserDTO.getSecondAuthStatus());
        }

        if (StringUtils.isNotBlank(certificateUserDTO.getFuzzySearch())) {
            queryWrapper.lambda().and(wrapper -> {
                wrapper.eq(CertificateUser::getContactInformation, TypeHandlerUtil.crypt(certificateUserDTO.getFuzzySearch()));
                wrapper.or();
                wrapper.like(CertificateUser::getFullName, certificateUserDTO.getFuzzySearch());
                wrapper.or();
                wrapper.eq(CertificateUser::getCardNumber, TypeHandlerUtil.crypt(certificateUserDTO.getFuzzySearch()));
                wrapper.or();
                wrapper.eq(CertificateUser::getOrderNumber, certificateUserDTO.getFuzzySearch());
                wrapper.or();
                if (CollectionUtil.isNotEmpty(certificateUserDTO.getCompanyIds())) {
                    wrapper.in(CertificateUser::getCompanyId, certificateUserDTO.getCompanyIds());
                    wrapper.or();
                }
            });
        }


        return queryWrapper;
    }

    @Override
    public List<CertificateUserVO> assembleBusinssData(List<CertificateUserVO> certificateUserVOList) {
        if (certificateUserVOList == null || certificateUserVOList.isEmpty()) {
            return null;
        }
        //证件信息
        List<Long> certificateIdList = certificateUserVOList.stream().map(CertificateUserVO::getCertificateId).collect(Collectors.toList());
        List<Certificate> certificateList = certificateService.list(null, certificateIdList);
        if (CollectionUtil.isNotEmpty(certificateList)) {
            for (Certificate certificate : certificateList) {
                for (CertificateUserVO certificateUserVO : certificateUserVOList) {
                    if (certificateUserVO.getCertificateId() != null && certificate.getId().equals(certificateUserVO.getCertificateId())) {
                        certificateUserVO.setCertificate(certificateService.doToVo(certificate));
                    }
                }
            }
        }


        //查询服务商信息
        List<Long> companyIds = certificateUserVOList.stream().map(CertificateUserVO::getCompanyId).collect(Collectors.toList());
        ServiceProviderDTO query = new ServiceProviderDTO();
        query.setIds(companyIds);
        log.info("查询服务商信息 start param is {}", JSONObject.toJSONString(query));
        R<List<ServiceProviderVO>> serviceProviderListR = serviceProviderFeign.queryServiceProvider(query);
        log.info("查询服务商信息 end   result is {}", JSONObject.toJSONString(serviceProviderListR));
        if (serviceProviderListR.getIsSuccess() && serviceProviderListR.getData() != null && !serviceProviderListR.getData().isEmpty()) {
            for (ServiceProviderVO serviceProviderVO : serviceProviderListR.getData()) {
                for (CertificateUserVO certificateUserVO : certificateUserVOList) {
                    if (serviceProviderVO.getId().equals(certificateUserVO.getCompanyId())) {
                        certificateUserVO.setServiceProviderVO(serviceProviderVO);
                    }
                }
            }
        }
        //场地信息
        if (certificateUserVOList.get(0).getExhibitionId() != null) {
            log.info("场地信息 start param is {}", certificateUserVOList.get(0).getExhibitionId());
            R<List<ExhibitionSpaceVO>> listR = exhibitionManageFeign.queryByExhibitionManageId(certificateUserVOList.get(0).getExhibitionId());
            log.info("场地信息 end   result is {}", JSONObject.toJSONString(listR));
            if (listR.getIsSuccess() && listR.getData() != null && !listR.getData().isEmpty()) {
                for (ExhibitionSpaceVO exhibitionSpaceVO : listR.getData()) {
                    for (CertificateUserVO certificateUserVO : certificateUserVOList) {
                        if (exhibitionSpaceVO != null && StringUtils.isNotBlank(exhibitionSpaceVO.getSpaceCode()) && exhibitionSpaceVO.getSpaceCode().equals(certificateUserVO.getSpaceCode())) {
                            certificateUserVO.setExhibitionSpaceVO(exhibitionSpaceVO);
                        }
                    }
                }
            }
        }
        //展会信息
        List<Long> exhibitionIds = certificateUserVOList.stream().map(CertificateUserVO::getExhibitionId).collect(Collectors.toList());
        ExhibitionManageQuery exhibitionManageQuery = new ExhibitionManageQuery();
        exhibitionManageQuery.setIds(exhibitionIds);
        log.info("展会信息 start param is {} ", JSONObject.toJSONString(exhibitionManageQuery));
        R<List<ExhibitionManageVO>> listR = exhibitionManageFeign.queryAllExhibitionManage(exhibitionManageQuery);
        log.info("展会信息 end result is {} ", JSONObject.toJSONString(listR));
        if (listR.getIsSuccess() && listR.getData() != null && !listR.getData().isEmpty()) {
            for (ExhibitionManageVO exhibitionManageVO : listR.getData()) {
                for (CertificateUserVO certificateUserVO : certificateUserVOList) {
                    if (exhibitionManageVO.getId().equals(certificateUserVO.getExhibitionId())) {
                        certificateUserVO.setExhibitionManageVO(exhibitionManageVO);
                    }
                }
            }
        }
        return certificateUserVOList;
    }

    @Override
    public Boolean clearCertificate(CertificateUserDTO certificateUserDTO) {
        List<CertificateUser> certificateUserList = list(null, certificateUserDTO.getIds());
        if (certificateUserList != null && !certificateUserList.isEmpty()) {
            for (CertificateUser certificateUser : certificateUserList) {
                certificateUser.setIsCancel(BusinessConstant.YES);
                certificateUser.setCertificateStatus(CertificateUserCertificateStatusEnum.END);
                updateById(certificateUser);
            }
        }
        return true;
    }

    @Override
    public Boolean lessCertificate(CertificateUserDTO certificateUserDTO) {
        List<CertificateUser> certificateUserList = list(null, certificateUserDTO.getIds());
        if (certificateUserList != null && !certificateUserList.isEmpty()) {
            for (CertificateUser certificateUser : certificateUserList) {
                certificateUser.setIsLoss(BusinessConstant.YES);
                certificateUser.setCertificateStatus(CertificateUserCertificateStatusEnum.END);
                updateById(certificateUser);
            }
        }
        return true;
    }


    @Override
    public Boolean addBackCertificate(CertificateUserDTO certificateUserDTO) {
        return null;
    }

    @Override
    public Boolean sycnAddBackSertificate(List<String> mobiles, List<String> cardNumbers, List<Long> companyIds, List<Long> exhibitionIdList) {
        if (CollectionUtil.isEmpty(mobiles) && CollectionUtil.isEmpty(cardNumbers) && CollectionUtil.isEmpty(companyIds)) {
            return false;
        }
        QueryWrapper<CertificateUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.and(wrapper -> {
            if (CollectionUtil.isNotEmpty(mobiles)) {
                List<String> privateMobiles = new ArrayList<>();
                for (String s : mobiles) {
                    privateMobiles.add(TypeHandlerUtil.crypt(s));
                }
                wrapper.lambda().in(CertificateUser::getContactInformation, privateMobiles);
                wrapper.or();
            }
            if (CollectionUtil.isNotEmpty(cardNumbers)) {
                List<String> privateCardNumbers = new ArrayList<>();
                for (String s : cardNumbers) {
                    privateCardNumbers.add(TypeHandlerUtil.crypt(s));
                }
                wrapper.lambda().in(CertificateUser::getCardNumber, privateCardNumbers);
                wrapper.or();
            }
            if (CollectionUtil.isNotEmpty(companyIds)) {
                wrapper.lambda().in(CertificateUser::getCompanyId, companyIds);
                wrapper.or();
            }
        });
        queryWrapper.lambda().in(CollectionUtil.isNotEmpty(exhibitionIdList), CertificateUser::getExhibitionId, exhibitionIdList);
        queryWrapper.and(wrapper -> {
            wrapper.lambda().ne(CertificateUser::getFirstAuthStatus, CertificateUserFirstAuthStatusEnum.CHECK_SUCC)
                    .or()
                    .ne(CertificateUser::getSecondAuthStatus, CertificateUserSecondAuthStatusEnum.CHECK_SUCC);
        });
//        queryWrapper.lambda().ne(CertificateUser::getFirstAuthStatus, CertificateUserFirstAuthStatusEnum.CHECK_SUCC);
//        queryWrapper.lambda().ne(CertificateUser::getSecondAuthStatus, CertificateUserSecondAuthStatusEnum.CHECK_SUCC);


        queryWrapper.lambda().eq(CertificateUser::getCertificateStatus, CertificateUserCertificateStatusEnum.AUTH);
        queryWrapper.lambda().eq(CertificateUser::getIsBlack, BusinessConstant.NO);
        queryWrapper.lambda().eq(CertificateUser::getIsPay, BusinessConstant.NO);
        queryWrapper.lambda().eq(CertificateUser::getIsDeleted, BusinessConstant.DELETE_NO);
        List<CertificateUser> modelList = list(queryWrapper);
        if (modelList != null && !modelList.isEmpty()) {
            for (CertificateUser certificateUser : modelList) {
                certificateUser.setIsBlack(BusinessConstant.YES);
                updateById(certificateUser);
            }
        }
        return true;
    }

    /**
     * 解绑除黑名单
     *
     * @param mobiles
     * @param cardNumbers
     * @param companyIds
     * @param exhibitionIdList
     * @return
     */
    @Override
    public Boolean sycnRemoveBackSertificate(List<String> mobiles, List<String> cardNumbers, List<Long> companyIds, List<Long> exhibitionIdList, List<Long> noInExhibitionIdList) {
        if (CollectionUtil.isEmpty(mobiles) && CollectionUtil.isEmpty(cardNumbers) && CollectionUtil.isEmpty(companyIds) && CollectionUtil.isEmpty(exhibitionIdList)) {
            return false;
        }
        QueryWrapper<CertificateUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.and(wrapper -> {
            if (CollectionUtil.isNotEmpty(mobiles)) {
                List<String> privateMobiles = new ArrayList<>();
                for (String s : mobiles) {
                    privateMobiles.add(TypeHandlerUtil.crypt(s));
                }
                wrapper.lambda().in(CertificateUser::getContactInformation, privateMobiles);
                wrapper.or();
            }
            if (CollectionUtil.isNotEmpty(cardNumbers)) {
                List<String> privateCardNumbers = new ArrayList<>();
                for (String s : cardNumbers) {
                    privateCardNumbers.add(TypeHandlerUtil.crypt(s));
                }
                wrapper.lambda().in(CertificateUser::getCardNumber, privateCardNumbers);
                wrapper.or();
            }

            if (CollectionUtil.isNotEmpty(companyIds)) {
                wrapper.lambda().in(CertificateUser::getCompanyId, companyIds);
                wrapper.or();
            }
        });

        if (CollectionUtil.isNotEmpty(exhibitionIdList)) {
            queryWrapper.lambda().in(CertificateUser::getExhibitionId, exhibitionIdList);
        }
        queryWrapper.lambda().notIn(CollectionUtil.isNotEmpty(noInExhibitionIdList), CertificateUser::getExhibitionId, noInExhibitionIdList);
        queryWrapper.and(wrapper -> {
            wrapper.lambda().ne(CertificateUser::getFirstAuthStatus, CertificateUserFirstAuthStatusEnum.CHECK_SUCC)
                    .or()
                    .ne(CertificateUser::getSecondAuthStatus, CertificateUserSecondAuthStatusEnum.CHECK_SUCC);
        });
        queryWrapper.lambda().eq(CertificateUser::getIsPay, BusinessConstant.NO);
        queryWrapper.lambda().eq(CertificateUser::getIsBlack, BusinessConstant.YES);
        queryWrapper.lambda().eq(CertificateUser::getCertificateStatus, CertificateUserCertificateStatusEnum.AUTH);
        queryWrapper.lambda().eq(CertificateUser::getIsDeleted, BusinessConstant.DELETE_NO);
        List<CertificateUser> modelList = list(queryWrapper);
        if (modelList != null && !modelList.isEmpty()) {
            for (CertificateUser certificateUser : modelList) {
                certificateUser.setIsBlack(BusinessConstant.NO);
                updateById(certificateUser);
            }
        }
        return true;
    }

    @Override
    public void drawOrderOfUser(CertificateOrderDTO certificateOrderDTO) {
        CertificateUserDTO modelDTO = new CertificateUserDTO();
        modelDTO.setOrderId(certificateOrderDTO.getId());
        List<CertificateUser> certificateUserList = list(modelDTO, null);
        if (CollectionUtil.isNotEmpty(certificateUserList)) {
            for (CertificateUser certificateUser : certificateUserList) {
                certificateUser.setDrawMobile(certificateOrderDTO.getDrawMobile());
                certificateUser.setDrawName(certificateOrderDTO.getDrawName());
                certificateUser.setDrawIdcard(certificateOrderDTO.getDrawIdcard());
                updateById(certificateUser);
            }
        }
    }

    @Override
    public void draw(CertificateUserDTO certificateUserDTO) {
        CertificateUser certificateUser = getByIdCache(certificateUserDTO.getId());
        if (certificateUser != null) {
            if (BusinessConstant.YES == certificateUser.getIsDraw()) {
                throw NoBackBizException.wrap("已领取");
            }
            certificateUser.setDrawMobile(certificateUserDTO.getDrawMobile());
            certificateUser.setDrawName(certificateUserDTO.getDrawName());
            certificateUser.setDrawIdcard(certificateUserDTO.getDrawIdcard());
            certificateUser.setIsDraw(BusinessConstant.YES);
            updateById(certificateUser);
        }
    }


    /**
     * 通用查询
     *
     * @param modelDTO DTO
     * @param ids      主键id集合
     * @return list
     */
    @Override
    public List<CertificateUser> list(CertificateUserDTO modelDTO, List<Long> ids) {
        return ((CertificateUserService) AopContext.currentProxy()).listOfCache(modelDTO, ids);
    }


    /**
     * 缓存查询
     *
     * @param modelDTO DTO
     * @param ids      主键id集合
     * @return list
     */
    @Override
    @Cache(key = "",
            magic = @Magic(
                    key = "{" +
                            "{'certificateId', #args[0]?.certificateId}," +
                            "{'principalType', #args[0]?.principalType}," +
                            "{'exhibitionId', #args[0]?.exhibitionId}," +
                            "{'companyId', #args[0]?.companyId}," +
                            "{'cardFront', #args[0]?.cardFront}," +
                            "{'cardBack', #args[0]?.cardBack}," +
                            "{'cardNumber', #args[0]?.cardNumber}," +
                            "{'fullName', #args[0]?.fullName}," +
                            "{'gender', #args[0]?.gender}," +
                            "{'contactInformation', #args[0]?.contactInformation}," +
                            "{'exhibitorId', #args[0]?.exhibitorId}," +
                            "{'booth', #args[0]?.booth}," +
                            "{'workCertificateImg', #args[0]?.workCertificateImg}," +
                            "{'remarks', #args[0]?.remarks}," +
                            "{'carNumber', #args[0]?.carNumber}," +
                            "{'carType', #args[0]?.carType}," +
                            "{'carSize', #args[0]?.carSize}," +
                            "{'cargoCapacity', #args[0]?.cargoCapacity}," +
                            "{'cargoMaterial', #args[0]?.cargoMaterial}," +
                            "{'handlingMode', #args[0]?.handlingMode}," +
                            "{'transportVariety', #args[0]?.transportVariety}," +
                            "{'workType', #args[0]?.workType}," +
                            "{'documentType', #args[0]?.documentType}," +
                            "{'certificateClassify', #args[0]?.certificateClassify}," +
                            "{'isPower', #args[0]?.isPower}," +
                            "{'powerClassify', #args[0]?.powerClassify}," +
                            "{'spaceCode', #args[0]?.spaceCode}," +
                            "{'businessLicense', #args[0]?.businessLicense}," +
                            "{'drivingLicense', #args[0]?.drivingLicense}," +
                            "{'informationStatistics', #args[0]?.informationStatistics}," +
                            "{'report', #args[0]?.report}," +
                            "{'specialCertificate', #args[0]?.specialCertificate}," +
                            "{'specialVehicleCertificate', #args[0]?.specialVehicleCertificate}," +
                            "{'yearlyInspection', #args[0]?.yearlyInspection}," +
                            "{'isEnabled', #args[0]?.isEnabled}," +
                            "{'firstAuthStatus', #args[0]?.firstAuthStatus}," +
                            "{'firstAuthText', #args[0]?.firstAuthText}," +
                            "{'firstAuthId', #args[0]?.firstAuthId}," +
                            "{'secondAuthStatus', #args[0]?.secondAuthStatus}," +
                            "{'secondAuthText', #args[0]?.secondAuthText}," +
                            "{'secondAuthId', #args[0]?.secondAuthId}," +
                            "{'isCancel', #args[0]?.isCancel}," +
                            "{'isLoss', #args[0]?.isLoss}," +
                            "{'isDraw', #args[0]?.isDraw}," +
                            "{'isBlack', #args[0]?.isBlack}," +
                            "{'isPay', #args[0]?.isPay}," +
                            "{'orderId', #args[0]?.orderId}," +
                            "{'comeInTime', #args[0]?.comeInTime}," +
                            "{'certificateType', #args[0]?.certificateType}," +
                            "{'workEndTime', #args[0]?.workEndTime}," +
                            "{'certificateStatus', #args[0]?.certificateStatus}," +
                            "{'workStartTime', #args[0]?.workStartTime}," +
                            "{'dataResource', #args[0]?.dataResource}," +
                            "{'isSycn', #args[0]?.isSycn}," +
                            "{'axleCount', #args[0]?.axleCount}," +
                            "{'dataResource', #args[0]?.dataResource}," +
                            "{'eUuid', #args[0]?.eUuid}," +
                            "{'eDataJson', #args[0]?.eDataJson}," +
                            "{'drawMobile', #args[0]?.drawMobile}," +
                            "{'drawName', #args[0]?.drawName}," +
                            "{'drawIdcard', #args[0]?.drawIdcard}," +
                            "{'id', #args[1]}" +
                            "}"))
    public List<CertificateUser> listOfCache(CertificateUserDTO modelDTO, List<Long> ids) {
        //查询
        CertificateUser certificateUser = new CertificateUser();
        if (modelDTO != null) {
            BeanUtils.copyProperties(modelDTO, certificateUser);
        }
        //查询加密处理
//        if (StringUtils.isNotBlank(certificateUser.getContactInformation())) {
//            certificateUser.setContactInformation(TypeHandlerUtil.crypt(certificateUser.getContactInformation()));
//        }
//        if (StringUtils.isNotBlank(certificateUser.getCardNumber())) {
//            certificateUser.setCardNumber(TypeHandlerUtil.crypt(certificateUser.getCardNumber()));
//        }
        QueryWrap<CertificateUser> queryWrapper = Wraps.q(certificateUser);
        if (ids != null && !ids.isEmpty()) {
            queryWrapper.lambda().in(CertificateUser::getId, ids);
        }
        if (modelDTO != null) {
            queryWrapper.lambda().in(CollectionUtil.isNotEmpty(modelDTO.getEUuidList()), CertificateUser::getEUuid, modelDTO.getEUuidList());
        }
        queryWrapper.lambda().eq(CertificateUser::getIsDeleted, BusinessConstant.DELETE_NO);
        List<CertificateUser> modelList = list(queryWrapper);
        return modelList;
    }


    /**
     * do转vo
     *
     * @param model model
     * @return modelVo
     */
    @Override
    public CertificateUserVO doToVo(CertificateUser model) {
        CertificateUserVO modelVo = new CertificateUserVO();
        BeanUtils.copyProperties(model, modelVo);
        modelVo.setId(model.getId());
        return modelVo;
    }

    /**
     * do转vo
     *
     * @param modelList modelList
     * @return list
     */
    @Override
    public List<CertificateUserVO> doToVos(List<CertificateUser> modelList) {
        if (modelList == null || modelList.isEmpty()) {
            return null;
        }
        List<CertificateUserVO> result = new ArrayList<>();
        for (CertificateUser model : modelList) {
            result.add(doToVo(model));
        }
        return result;
    }

    @Override
    public CacheKeyBuilder getCacheKeyBuilder() {
        return new CertificateUserCacheKeyBuilder();
    }
}
